/*
 * Created by Jaren at 2023/6/1 15:20
 */
import 'dart:typed_data';

import 'package:binary/src/boxed_int.dart';
import 'package:inmotion_protocol/common/product_model.dart';
import 'package:inmotion_protocol/common/product_version.dart';
import 'package:inmotion_protocol/lorin/bean/euc/v13/v13_settings.dart';
import 'package:inmotion_protocol/util/byte_util.dart';

class V14Settings extends V13Settings {
  static const int speedUnitKmph = 0; // 车辆速度单位，Km/h
  static const int speedUnitMph = 1; // 车辆速度单位，mph

  Uint4 speedUnit = Uint4(0);

  // 双电池模式
  Uint16 twoBatteryMode = Uint16(0);

  V14Settings(ProductModel model, VersionWrapper version) : super(model, version);

  @override
  void initCompact() {
    compact = _V14SettingsDefault();
  }

  @override
  String toString() {
    return 'V14Settings{ speedUnit: $speedUnit, twoBatteryMode: $twoBatteryMode, ${super.toString()}}';
  }
}

class _V14SettingsDefault extends V13SettingsV1_5ImplDelegate {
  @override
  void fromBytes(V13Settings output, Uint8ClampedList bytes, int offset) {
    super.fromBytes(output, bytes, offset);
    if (bytes.length < offset + length()) {
      return;
    }

    output as V14Settings;

    offset += 34;
    // 速度单位
    output.speedUnit = ByteUtil.bitValue(bytes[offset], 7, 1);
    offset ++;
    output.twoBatteryMode = ByteUtil.bytes2Uint16Le(bytes, offset);
    print("858--857: ${output.twoBatteryMode}");
  }
}
